package com.mxf.code.handler;

import com.mxf.code.common.ResponseResult;
import com.mxf.code.util.WebUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author : [mxf]
 * @version : [v1.0]
 * @className : Acc
 * @description : [描述说明该类的功能]
 * @createTime : [2022/9/5 16:57]
 * @updateUser : [mxf]
 * @updateTime : [2022/9/5 16:57]
 * @updateRemark : [描述说明本次修改内容]
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResponseResult<String> responseResult = new ResponseResult<>(HttpStatus.FORBIDDEN.value(), "权限不足");

        WebUtils.renderString(response, responseResult.toJsonString());
    }
}
